package com.lwkjgf.workplace.main

import com.example.doctor.tablayout.ListVals
import com.google.android.material.tabs.TabLayout
import com.lwkjgf.userterminal.common.viewpager.BaseFragmentAdapter
import com.lwkjgf.workplace.R
import com.lwkjgf.workplace.base.BaseMvpActivity
import com.lwkjgf.workplace.main.presenter.MainPresenter
import com.lwkjgf.workplace.main.view.IMainView
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : BaseMvpActivity<MainPresenter?>(), IMainView {
    override fun getLayoutId(): Int {
        return R.layout.activity_main
    }

    override fun initView() {
        vpContent.offscreenPageLimit = 4
        vpContent.adapter = BaseFragmentAdapter(this.supportFragmentManager, ListVals.getFragments(), ListVals.getTitles())
        tablayout.setupWithViewPager(vpContent)
        tablayout.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener{
            override fun onTabReselected(tab: TabLayout.Tab?) {

            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {

            }

            override fun onTabSelected(tab: TabLayout.Tab) {
               /* if(1==tab.position){
                    EventBus.getDefault().post(UserMoney())
                }*/
            }
        })
        initTabs()
        tablayout.selectTab(tablayout.getTabAt(0))
    }
    //初始化tab，设置图标和自定义布局，注意顺序和某些语句。
    private fun initTabs() {
        val icons = ListVals.getIcons()
        for (i in 0 until tablayout.tabCount) {
            tablayout.getTabAt(i)!!.setIcon(icons[i])
            /*if (i == 2) {
                tablayout.getTabAt(i)!!.setCustomView(R.layout.tabmain_item1)
            } else {
                tablayout.getTabAt(i)!!.setCustomView(R.layout.tabmain_item)
            }*/
            tablayout.getTabAt(i)!!.setCustomView(R.layout.tabmain_item)
        }
    }
    override fun initData() {}
}